home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap09 / howto03 / delphi10 / cciccinf.~pa < prev    next >
Encoding:
Text File  |  1996-02-15  |  11.3 KB  |  342 lines

  1. unit Cciccinf;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Grids, Outline, CCWSock;
  8.  
  9. type
  10.   TCCICInfoDlg = class(TForm)
  11.     Panel1: TPanel;
  12.     BitBtn1: TBitBtn;
  13.     BitBtn2: TBitBtn;
  14.     Panel4: TPanel;
  15.     ListBox2: TListBox;
  16.     Panel2: TPanel;
  17.     Edit1: TEdit;
  18.     Panel3: TPanel;
  19.     Edit2: TEdit;
  20.     Panel5: TPanel;
  21.     Edit3: TEdit;
  22.     Panel8: TPanel;
  23.     Edit4: TEdit;
  24.     Panel9: TPanel;
  25.     Edit5: TEdit;
  26.     Panel6: TPanel;
  27.     Outline1: TOutline;
  28.     Label1: TLabel;
  29.     Label2: TLabel;
  30.     Button1: TButton;
  31.     Button2: TButton;
  32.     Button3: TButton;
  33.     Button4: TButton;
  34.     procedure Button1Click(Sender: TObject);
  35.     procedure ListBox2Click(Sender: TObject);
  36.     procedure BitBtn1Click(Sender: TObject);
  37.     procedure BitBtn2Click(Sender: TObject);
  38.     procedure Edit4Exit(Sender: TObject);
  39.     procedure Button2Click(Sender: TObject);
  40.     procedure Button3Click(Sender: TObject);
  41.     procedure Button4Click(Sender: TObject);
  42.   private
  43.     { Private declarations }
  44.   public
  45.     { Public declarations }
  46.   end;
  47.  
  48. var
  49.   CCICInfoDlg: TCCICInfoDlg;
  50.  
  51. implementation
  52.  
  53. uses CCICCFrm;
  54.  
  55. {$R *.DFM}
  56. procedure TCCICInfoDlg.Button1Click(Sender: TObject);
  57. var TempSocket : TCCSocket; { Used for IP Address info }
  58.     DataBuffer : array[ 0 .. 256 ] of char;
  59. begin
  60.   case Tag of
  61.     1 : begin  { Get IP Address Mode }
  62.           { Create the dummy socket }
  63.           TempSocket := TCCSocket.Create( Self );
  64.           TempSocket.Parent := Self;
  65.           { Use it to get the info }
  66.           with TempSocket do
  67.           begin
  68.             { Move the IP address into the data buffer }
  69.             StrPCopy( DataBuffer , Edit1.Text );
  70.             { Turn it into a real IP address in binary form }
  71.             Socket_IP_Address.Socket_Address.Full_Internet_Address :=
  72.              inet_addr( DataBuffer );
  73.             { If not found then do remote lookup }
  74.             if Socket_IP_Address.Socket_Address.Full_Internet_Address = INADDR_NONE then
  75.             begin
  76.               { Call blocking function on IP name }
  77.               Socket_Host_Entry := gethostbyname( DataBuffer );
  78.               { If still no good then error out and exit }
  79.               if Socket_Host_Entry = nil then
  80.               begin
  81.                 Edit2.Text := 'Could Not Convert Host Name';
  82.                 Edit3.Text := '';
  83.               end
  84.               else
  85.               begin
  86.                 { Otherwise get the address }
  87.                 Socket_IP_Address.Socket_Address :=
  88.                  Socket_Host_Entry^.Host_Address^^;
  89.                 Edit2.Text :=
  90.                  IntToStr( Socket_IP_Address.Socket_Address.Net_Byte ) + '.' +
  91.                  IntToStr( Socket_IP_Address.Socket_Address.Host_Byte ) + '.' +
  92.                  IntToStr( Socket_IP_Address.Socket_Address.Local_Host_Byte ) +
  93.                  '.' + IntToStr(
  94.                  Socket_IP_Address.Socket_Address.Local_Machine_Byte );
  95.                 Edit3.Text :=
  96.                  IntToStr( Socket_IP_Address.Socket_Address.
  97.                             Full_Internet_Address );
  98.               end;
  99.             end;
  100.           end;
  101.           { Free the dummy socket }
  102.           TempSocket.Free;
  103.         end;
  104.     2 : begin { Anonymous login punch }
  105.           Edit3.Text := 'anonymous';
  106.           CurrentRealPWString := CurrentPassWordString;
  107.           case PasswordControlVector of
  108.             1 : Edit4.Text := CurrentPassWordString;
  109.             2 : Edit4.Text := '**********';
  110.           end;
  111.         end;
  112.   end;
  113. end;
  114.  
  115. procedure TCCICInfoDlg.ListBox2Click(Sender: TObject);
  116. begin
  117.   { Use Tag vector to find out how to interpret a click }
  118.   case Tag of
  119.     2 : begin
  120.           { If nothing in list box then exit }
  121.           if ListBox2.ItemIndex = -1 then exit;
  122.           { Use the data in the Working FTP Site List TList }
  123.           with PConnectionsRecord(
  124.            TheWorkingFTPSL.Items[ ListBox2.ItemIndex ] )^ do
  125.           begin
  126.               Edit1.Text := CProfile;
  127.               Edit2.Text := CIPAddress;
  128.               Edit3.Text := CUserName;
  129.               CurrentRealPWString := CPassword;
  130.               case PasswordControlVector of
  131.                 1 : Edit4.Text := CPassword;
  132.                 2 : Edit4.Text := '**********';
  133.               end;
  134.               Edit5.Text := CStartDir;
  135.           end;
  136.         end;
  137.   end;
  138. end;
  139.  
  140. { This procedure saves the newly modified list of stuff to its base }
  141. procedure TCCICInfoDlg.BitBtn1Click(Sender: TObject);
  142. var Counter_1  : SmallInt;            { Loop counter        }
  143.     ThePointer : PConnectionsRecord; { Generic TCR Pointer }
  144. begin
  145.   { Use the tag vector to find out what to do }
  146.   case Tag of
  147.     2 : begin { Do FTP Site List }
  148.           { dispose the old FTP site list's pointers }
  149.           for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  150.           begin
  151.             Dispose( PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] ));
  152.           end;
  153.           { Clear the lists }
  154.           TheFTPSiteList.Clear;
  155.           CCInetCCForm.ComboBox1.Clear;
  156.           { Add the new info }
  157.           for Counter_1 := 0 to TheWorkingFTPSL.Count - 1 do
  158.           begin
  159.             { Create a new pointer }
  160.             New( ThePointer );
  161.             { Move the data into it }
  162.             ThePointer^ :=
  163.              PConnectionsRecord( TheWorkingFTPSL.Items[ Counter_1 ] )^;
  164.             { Add the item }
  165.             TheFTPSiteList.Add( ThePointer );
  166.             CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  167.              TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  168.           end;
  169.           CCINetCCForm.ComboBox1.ItemIndex := 0;
  170.         end;
  171.   end;
  172.   { Leave }
  173.   Close;
  174. end;
  175.  
  176. { This method cancels any changes made from entries in current setup & exits}
  177. procedure TCCICInfoDlg.BitBtn2Click(Sender: TObject);
  178. var Counter_1  : SmallInt;            { Loop counter        }
  179.     ThePointer : PConnectionsRecord; { Generic TCR Pointer }
  180. begin
  181.   { Use Tag vector do decide what to reset }
  182.   case Tag of
  183.     2 : begin { Reset FTP Site list }
  184.           { Dispose of all the old pointers }
  185.           for Counter_1 := 0 to TheWorkingFTPSL.Count - 1 do
  186.           begin
  187.             Dispose( PConnectionsRecord( TheWorkingFTPSL.Items[ Counter_1 ] ));
  188.           end;
  189.           { Clear the working list }
  190.           TheWorkingFTPSL.Clear;
  191.           { Clear the listbox }
  192.           ListBox2.Clear;
  193.           { Then rebuild the working list and display listbox }
  194.           for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  195.           begin
  196.             { Create the record }
  197.             New( ThePointer );
  198.             { Move data in }
  199.             ThePointer^ :=
  200.              PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] )^;
  201.             { Add the pointer to the list }
  202.             TheWorkingFTPSL.Add( ThePointer );
  203.             { Add the profile name to the list }
  204.             ListBox2.Items.Add( PConnectionsRecord(
  205.              TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  206.           end;
  207.         end;
  208.   end;
  209.   { Leave }
  210.   Close;
  211. end;
  212.  
  213. procedure TCCICInfoDlg.Edit4Exit(Sender: TObject);
  214. begin
  215.   { Use tag vector to determine action }
  216.   case Tag of
  217.     2 : begin
  218.           { If Edit4 is modified then mangle pw }
  219.           if Edit4.Modified then
  220.           begin
  221.             { Save pw in either case, but mangle if masked }
  222.             case PasswordControlVector of
  223.               1 : CurrentRealPWString := Edit4.Text;
  224.               2 : begin
  225.                     CurrentRealPWString := Edit4.Text;
  226.                     Edit4.Text := '***********';
  227.                   end;
  228.             end;
  229.           end;
  230.         end;
  231.   end;
  232. end;
  233.  
  234. { Add button; do various add actions }
  235. procedure TCCICInfoDlg.Button2Click(Sender: TObject);
  236. var ThePointer : PConnectionsRecord; { PCR Pointer }
  237. begin
  238.   { Tag vector control as usual }
  239.   case Tag of
  240.     2 : begin { add new FTP site list entry }
  241.           { Creat new PCR pointer }
  242.           New( ThePointer );
  243.           { Add in the data from the text fields }
  244.           with ThePointer^ do
  245.           begin
  246.             CProfile   := Edit1.Text;
  247.             CIPAddress := Edit2.Text;;
  248.             CUserName  := Edit3.Text;
  249.             { Put in the real pw string }
  250.             CPassword  := CurrentRealPWString;
  251.             CStartDir  := Edit5.Text;
  252.           end;
  253.           { Add pointer to working list }
  254.           TheWorkingFTPSL.Add( ThePointer );
  255.           { Add it to the listbox }
  256.           ListBox2.Items.Add( ThePointer^.CProfile );
  257.           { And set the pointer to it }
  258.           ListBox2.ItemIndex := ListBox2.Items.Count - 1;
  259.         end;
  260.   end;
  261. end;
  262.  
  263. { This is the modify button }
  264. procedure TCCICInfoDlg.Button3Click(Sender: TObject);
  265. begin
  266.   { Use Tag vector as usual }
  267.   case Tag of
  268.     2 : begin
  269.           { if nothing to modify the exit }
  270.           if ListBox2.ItemIndex = -1 then exit;
  271.           { get record of current listbox pointer & put in data }
  272.           with PConnectionsRecord(
  273.            TheWorkingFTPSL.Items[ ListBox2.ItemIndex ] )^ do
  274.           begin
  275.             CProfile   := Edit1.Text;
  276.             CIPAddress := Edit2.Text;;
  277.             CUserName  := Edit3.Text;
  278.             { Put in the real pw string }
  279.             CPassword  := CurrentRealPWString;
  280.             CStartDir  := Edit5.Text;
  281.           end;
  282.           { Make sure the display matches the edit control }
  283.           ListBox2.Items[ ListBox2.ItemIndex ] := Edit1.Text;
  284.         end;
  285.   end;
  286. end;
  287.  
  288. { This is the delete button }
  289. procedure TCCICInfoDlg.Button4Click(Sender: TObject);
  290. var MessageString : string; { string holder }
  291. begin
  292.   { Use tag control vector }
  293.   case Tag of
  294.     2 : begin
  295.           { If nothing to delete then leave }
  296.           if Listbox2.Itemindex = -1 then exit;
  297.           { Set up display }
  298.           MessageString := 'Delete Entry ' + Edit1.Text + '?';
  299.           { Display message box and get result }
  300.           if MessageDlg( MessageString , mtConfirmation , mbYesNoCancel , 0 )
  301.            = mrYes then
  302.           begin
  303.             { if ok delete then remove item from working sl }
  304.             TheWorkingFTPSL.Delete( ListBox2.ItemIndex );
  305.             { delete from listbox }
  306.             ListBox2.Items.Delete( ListBox2.ItemIndex );
  307.             { If nothing left set itemindex and clear edits }
  308.             if ListBox2.Items.Count = 0 then
  309.             begin
  310.               ListBox2.ItemIndex := -1;
  311.               Edit1.Text := '';
  312.               Edit2.Text := '';
  313.               Edit3.Text := '';
  314.               Edit4.Text := '';
  315.               Edit5.Text := '';
  316.             end
  317.             else
  318.             begin
  319.               { Reset listbox pointer }
  320.               ListBox2.ItemIndex  := 0;
  321.               { and reset display to new item }
  322.               with PConnectionsRecord(
  323.                TheWorkingFTPSL.Items[ ListBox2.ItemIndex ] )^ do
  324.               begin
  325.                 Edit1.Text := CProfile;
  326.                 Edit2.Text := CIPAddress;
  327.                 Edit3.Text := CUserName;
  328.                 CurrentRealPWString := CPassword;
  329.                 case PasswordControlVector of
  330.                   1 : Edit4.Text := CPassword;
  331.                   2 : Edit4.Text := '**********';
  332.                 end;
  333.                 Edit5.Text := CStartDir;
  334.               end;
  335.             end;
  336.           end;
  337.         end;
  338.   end;
  339. end;
  340.  
  341. end.
  342.